package com.wen.springbootorderserver.service;

import com.wen.springbootorderserver.dao.OrderDatabase;
import com.wen.springbootorderserver.dao.OrderMqService;
import com.wen.springbootorderserver.pojo.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

@Service
public class MqOrderService {

    @Autowired
    private OrderDatabase orderDatabase;
    @Autowired
    private OrderMqService mqService;

    //创建订单
    @Transactional(rollbackFor = Exception.class)
    public void createOrder(Orders order)throws Exception{

        //添加订单
        orderDatabase.saveOrder(order);

        //发布消息到交换机
        mqService.sengMessage(order);

    }



}
